package com.collection;

import com.domin.Student;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class IteratorTest {
    public static void main(String[] args) {
        Collection<Student> c=new ArrayList();
        c.add(new Student("张三",25));
        c.add(new Student("张四",66));
        c.add(new Student("张五",88));

        // 集合遍历，使用迭代器
        Iterator<Student> it=c.iterator();
        while (it.hasNext()){
            Student stu=it.next();
            System.out.println(stu);
        }

        // 集合遍历，使用增强for循环
        for (Student student : c) {
            System.out.println(student);
        }

        // foreach方法遍历
        c.forEach(student -> System.out.println(student));

    }
}
